package top.txl.controller;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.txl.entity.Orders;
import top.txl.entity.R;
import top.txl.mapper.LoginMapper;
import top.txl.service.LoginService;
import top.txl.service.OrderDetailService;
import top.txl.service.OrderService;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private LoginService loginService;

    @PostMapping("/save")
    public R<String> save(HttpServletRequest request, @RequestBody Orders order){
        log.info("order");
        String jwt = request.getHeader("Authorization");
        Integer userId = loginService.findUserByToken(jwt);

        if(userId != null){
            order.setUserId(userId);

            orderService.save(order);
        }

        return R.success("成功");
    }
}
